2 * Copyright (c) 2013-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 #import "KNAppDelegate.h"
26 #import "KDSecCircle.h"
27 #import "KDCirclePeer.h"
28 #import "NSDictionary+compactDescription.h"
29 #import <AOSUI/NSImageAdditions.h>
30 #import <AppleSystemInfo/AppleSystemInfo.h>
31 #import <Security/SecFrameworkStrings.h>
33 #import <utilities/debugging.h>
35 #import <Accounts/Accounts.h>
36 #import <AOSAccounts/MobileMePrefsCoreAEPrivate.h>
37 #import <AOSAccounts/MobileMePrefsCore.h>
38 #import <AOSAccounts/ACAccountStore+iCloudAccount.h>
39 #import <AOSAccounts/iCloudAccount.h>
41 #include <msgtracer_client.h>
42 #include <msgtracer_keys.h>
43 #include <CrashReporterSupport/CrashReporterSupportPrivate.h>
44 #import <ProtectedCloudStorage/CloudIdentity.h>
45 #import "CoreCDP/CDPFollowUpController.h"
46 #import "CoreCDP/CDPFollowUpContext.h"
48 static const char * const kLaunchLaterXPCName = "com.apple.security.Keychain-Circle-Notification-TICK";
49 static const NSString * const kKickedOutKey = @"KickedOut";
50 static const NSString * const kValidOnlyOutOfCircleKey = @"ValidOnlyOutOfCircle";
51 static const NSString * const kPasswordChangedOrTrustedDeviceChanged = @"TDorPasswordChanged";
52 static NSString *prefpane = @"/System/Library/PreferencePanes/iCloudPref.prefPane";
53 #define kPublicKeyNotAvailable "com.apple.security.publickeynotavailable"
54 static NSString *KeychainPCDetailsAEAction = @"AKPCDetailsAEAction";
56 @implementation KNAppDelegate
58 static NSUserNotificationCenter *appropriateNotificationCenter()
60 return [NSUserNotificationCenter _centerForIdentifier: @"com.apple.security.keychain-circle-notification"
61 type: _NSUserNotificationCenterTypeSystem];
65 -(void) startFollowupKitRepair
67 NSError *localError = NULL;
68 CDPFollowUpController *cdpd = [[CDPFollowUpController alloc] init];
69 CDPFollowUpContext *context = [CDPFollowUpContext contextForStateRepair];
70 [cdpd postFollowUpWithContext:context error:&localError ];
72 secnotice("kcn", "request to CoreCDP to follow up failed: %@", localError);
75 secnotice("kcn", "CoreCDP handling follow up");
78 - (void) handleDismissedNotification
80 ACAccountStore *accountStore = [[ACAccountStore alloc] init];
81 ACAccount *primaryiCloudAccount = nil;
83 if ([accountStore respondsToSelector:@selector(icaPrimaryAppleAccount)]){
84 primaryiCloudAccount = [accountStore icaPrimaryAppleAccount];
87 if(primaryiCloudAccount){
88 bool localICDP = false;
89 NSString *dsid = primaryiCloudAccount.icaPersonID;
91 NSDictionary *options = @{ (__bridge id) kPCSSetupDSID : dsid, };
92 PCSIdentitySetRef identity = PCSIdentitySetCreate((__bridge CFDictionaryRef) options, NULL, NULL);
95 localICDP = PCSIdentitySetIsICDP(identity, NULL);
100 secnotice("kcn", "handling dismissed notification, would start a follow up");
101 [self startFollowupKitRepair];
105 secerror("unable to find primary account");
109 - (void) notifyiCloudPreferencesAbout: (NSString *) eventName
111 if (eventName == nil)
114 secnotice("kcn", "notifyiCloudPreferencesAbout %@", eventName);
116 NSString *accountID = (__bridge_transfer NSString*)(MMCopyLoggedInAccountFromAccounts());
117 ACAccountStore *accountStore = [[ACAccountStore alloc] init];
118 ACAccount *primaryiCloudAccount = nil;
120 if ([accountStore respondsToSelector:@selector(icaPrimaryAppleAccount)]){
121 primaryiCloudAccount = [accountStore icaPrimaryAppleAccount];
124 if(primaryiCloudAccount){
126 BOOL createdAEDesc = createAEDescWithAEActionAndAccountID((__bridge NSString *) kMMServiceIDKeychainSync, eventName, accountID, &aeDesc);
129 NSArray *prefPaneURL = [NSArray arrayWithObject: [NSURL fileURLWithPath: prefpane ]];
131 LSLaunchURLSpec lsSpec = {
133 .itemURLs = (__bridge CFArrayRef)prefPaneURL,
134 .passThruParams = &aeDesc,
135 .launchFlags = kLSLaunchDefaults | kLSLaunchAsync,
139 OSErr err = LSOpenFromURLSpec(&lsSpec, NULL);
142 secerror("Can't send event %@, err=%d", eventName, err);
143 AEDisposeDesc(&aeDesc);
145 secerror("unable to create and send aedesc for account: '%@' and action: '%@'\n", primaryiCloudAccount, eventName);
149 secerror("unable to find primary account");
154 NSDate *nowish = [NSDate new];
156 self.state = [KNPersistentState loadFromStorage];
157 if ([nowish compare:self.state.pendingApplicationReminder] != NSOrderedAscending) {
158 secnotice("kcn", "REMINDER TIME: %@ >>> %@", nowish, self.state.pendingApplicationReminder);
160 // self.circle.rawStatus might not be valid yet
161 if (SOSCCThisDeviceIsInCircle(NULL) == kSOSCCRequestPending) {
162 // Still have a request pending, send reminder, and also in addtion to the UI
163 // we need to send a notification for iCloud pref pane to pick up
164 CFNotificationCenterPostNotificationWithOptions(
165 CFNotificationCenterGetDistributedCenter(),
166 CFSTR("com.apple.security.secureobjectsync.pendingApplicationReminder"),
167 (__bridge const void *) [self.state.applicationDate description], NULL, 0
170 [self postApplicationReminder];
171 self.state.pendingApplicationReminder = [nowish dateByAddingTimeInterval:[self getPendingApplicationReminderInterval]];
172 [self.state writeToStorage];
178 - (void) scheduleActivityAt: (NSDate *) time
180 if ([time compare:[NSDate distantFuture]] != NSOrderedSame) {
181 NSTimeInterval howSoon = [time timeIntervalSinceNow];
183 [self scheduleActivityIn:ceil(howSoon)];
190 - (void) scheduleActivityIn: (int) alertInterval
192 xpc_object_t options = xpc_dictionary_create(NULL, NULL, 0);
193 xpc_dictionary_set_uint64(options, XPC_ACTIVITY_DELAY, alertInterval);
194 xpc_dictionary_set_uint64(options, XPC_ACTIVITY_GRACE_PERIOD, XPC_ACTIVITY_INTERVAL_1_MIN);
195 xpc_dictionary_set_bool (options, XPC_ACTIVITY_REPEATING, false);
196 xpc_dictionary_set_bool (options, XPC_ACTIVITY_ALLOW_BATTERY, true);
197 xpc_dictionary_set_string(options, XPC_ACTIVITY_PRIORITY, XPC_ACTIVITY_PRIORITY_UTILITY);
199 xpc_activity_register(kLaunchLaterXPCName, options, ^(xpc_activity_t activity) {
205 - (NSTimeInterval) getPendingApplicationReminderInterval
207 if (self.state.pendingApplicationReminderInterval)
208 return [self.state.pendingApplicationReminderInterval doubleValue];
214 // Copied from sysdiagnose/src/utils.m
215 static bool isAppleInternal(void)
217 static bool ret = false;
218 static dispatch_once_t onceToken;
219 dispatch_once(&onceToken, ^{
221 ret = CRIsAppleInternal();
223 ret = CRHasBeenAppleInternalRecently();
230 #define ICKC_EVENT_DISABLED "com.apple.security.secureobjectsync.disabled"
231 #define ICKC_EVENT_DEPARTURE_REASON "com.apple.security.secureobjectsync.departurereason"
232 #define ICKC_EVENT_NUM_PEERS "com.apple.security.secureobjectsync.numcircledevices"
234 - (void) applicationDidFinishLaunching: (NSNotification *) aNotification
236 appropriateNotificationCenter().delegate = self;
238 secnotice("kcn", "Posted at launch: %@", appropriateNotificationCenter().deliveredNotifications);
240 //register for public key not available notification, if occurs KCN can react
241 notify_register_dispatch(kPublicKeyNotAvailable, &out_taken, dispatch_get_main_queue(), ^(int token) {
242 CFErrorRef err = NULL;
243 KNAppDelegate *me = self;
244 enum DepartureReason departureReason = SOSCCGetLastDepartureReason(&err);
245 SOSCCStatus currentCircleStatus = SOSCCThisDeviceIsInCircle(&err);
246 me.state = [KNPersistentState loadFromStorage];
248 secnotice("kcn", "got public key not available notification, but won't send notification unless circle transition matches");
249 secnotice("kcn", "current circle status: %d, current departure reason: %d, last circle status: %d", currentCircleStatus, departureReason, me.state.lastCircleStatus);
251 if(currentCircleStatus == kSOSCCError && me.state.lastCircleStatus == kSOSCCInCircle && (departureReason == kSOSNeverLeftCircle)) {
252 secnotice("kcn", "circle status went from in circle to not in circle");
253 [self postRequirePassword];
255 me.state.lastCircleStatus = currentCircleStatus;
257 [me.state writeToStorage];
260 self.viewedIds = [NSMutableSet new];
261 self.circle = [KDSecCircle new];
262 KNAppDelegate *me = self;
264 [self.circle addChangeCallback:^{
265 secnotice("kcn", "{ChangeCallback}");
267 CFErrorRef err = NULL;
269 enum DepartureReason departureReason = SOSCCGetLastDepartureReason(&err);
271 NSDate *nowish = [NSDate date];
272 SOSCCStatus circleStatus = SOSCCThisDeviceIsInCircle(&err);
273 me.state = [KNPersistentState loadFromStorage];
274 secnotice("kcn", "applicationDidFinishLaunching");
276 if(circleStatus == kSOSCCError && me.state.lastCircleStatus == kSOSCCInCircle && (departureReason == kSOSNeverLeftCircle)) {
277 CFErrorRef error = NULL;
278 SOSCCStatus currentCircleStatus = SOSCCThisDeviceIsInCircle(&error);
279 CFIndex errorCode = CFErrorGetCode(error);
281 if(errorCode == kSOSErrorPublicKeyAbsent){
282 secnotice("kcn", "We need the password to re-validate ourselves - it's changed on another device");
283 me.state.lastCircleStatus = currentCircleStatus;
284 [me.state writeToStorage];
285 [me postRequirePassword];
289 // Pending application reminder
290 secnotice("kcn", "{ChangeCallback} scheduleActivity %@", me.state.pendingApplicationReminder);
291 if (circleStatus == kSOSCCRequestPending)
292 [me scheduleActivityAt:me.state.pendingApplicationReminder];
295 // No longer in circle?
296 if ((me.state.lastCircleStatus == kSOSCCInCircle && (circleStatus == kSOSCCNotInCircle || circleStatus == kSOSCCCircleAbsent)) ||
297 (me.state.lastCircleStatus == kSOSCCCircleAbsent && circleStatus == kSOSCCNotInCircle && me.state.absentCircleWithNoReason) ||
298 me.state.debugLeftReason) {
299 enum DepartureReason reason = kSOSNeverLeftCircle;
300 if (me.state.debugLeftReason) {
301 reason = [me.state.debugLeftReason intValue];
302 me.state.debugLeftReason = nil;
303 [me.state writeToStorage];
305 reason = SOSCCGetLastDepartureReason(&err);
306 if (reason == kSOSDepartureReasonError) {
307 secnotice("kcn", "SOSCCGetLastDepartureReason err: %@", err);
309 if (err) CFRelease(err);
312 if (reason != kSOSDepartureReasonError) {
313 // Post kick-out alert
315 // <rdar://problem/20862435> MessageTracer data to find out how many users were dropped & reset
316 msgtracer_domain_t domain = msgtracer_domain_new(ICKC_EVENT_DISABLED);
317 msgtracer_msg_t mt_msg = NULL;
320 mt_msg = msgtracer_msg_new(domain);
325 msgtracer_set(mt_msg, kMsgTracerKeySignature, ICKC_EVENT_DEPARTURE_REASON);
326 snprintf(s, sizeof(s), "%u", reason);
327 msgtracer_set(mt_msg, kMsgTracerKeyValue, s);
329 int64_t num_peers = 0;
330 CFArrayRef peerList = SOSCCCopyPeerPeerInfo(NULL);
332 num_peers = CFArrayGetCount(peerList);
333 if (num_peers > 99) {
334 // Round down # peers to 2 significant digits
336 for (factor = 10; num_peers >= 100*factor; factor *= 10) ;
337 num_peers = (num_peers / factor) * factor;
341 msgtracer_set(mt_msg, kMsgTracerKeySignature2, ICKC_EVENT_NUM_PEERS);
342 snprintf(s, sizeof(s), "%lld", num_peers);
343 msgtracer_set(mt_msg, kMsgTracerKeyValue2, s);
345 msgtracer_set(mt_msg, kMsgTracerKeySummarize, "NO");
346 msgtracer_log(mt_msg, ASL_LEVEL_DEBUG, "");
350 // 1. Write here due to [me timerCheck] => [KNPersistentState loadFromStorage] below?!?
351 // 2. Or change call order of timerCheck, pendingApplication reminder below???
352 me.state.absentCircleWithNoReason = (circleStatus == kSOSCCCircleAbsent && reason == kSOSNeverLeftCircle);
353 [me.state writeToStorage];
354 secnotice("kcn", "{ChangeCallback} departure reason %d", reason);
357 case kSOSDiscoveredRetirement:
358 case kSOSLostPrivateKey:
359 case kSOSWithdrewMembership:
360 case kSOSNeverAppliedToCircle:
363 case kSOSNeverLeftCircle:
364 case kSOSMembershipRevoked:
365 case kSOSLeftUntrustedCircle:
367 [me postKickedOutAlert: reason];
374 // Circle applications: pending request(s) started / completed
375 if (me.circle.rawStatus != me.state.lastCircleStatus) {
376 SOSCCStatus lastCircleStatus = me.state.lastCircleStatus;
377 me.state.lastCircleStatus = circleStatus;
379 if (lastCircleStatus != kSOSCCRequestPending && circleStatus == kSOSCCRequestPending) {
380 secnotice("kcn", "{ChangeCallback} Pending request START");
381 me.state.applicationDate = nowish;
382 me.state.pendingApplicationReminder = [me.state.applicationDate dateByAddingTimeInterval:[me getPendingApplicationReminderInterval]];
383 [me.state writeToStorage]; // FIXME: move below? might be needed for scheduleActivityAt...
384 [me scheduleActivityAt:me.state.pendingApplicationReminder];
387 if (lastCircleStatus == kSOSCCRequestPending && circleStatus != kSOSCCRequestPending) {
388 secnotice("kcn", "Pending request completed");
389 me.state.applicationDate = [NSDate distantPast];
390 me.state.pendingApplicationReminder = [NSDate distantFuture];
391 [me.state writeToStorage];
394 NSUserNotificationCenter *noteCenter = appropriateNotificationCenter();
395 for (NSUserNotification *note in noteCenter.deliveredNotifications) {
396 if (note.userInfo[(NSString*) kValidOnlyOutOfCircleKey] && note.userInfo[@"ApplicationReminder"]) {
397 secnotice("kcn", "{ChangeCallback} Removing notification %@", note);
398 [appropriateNotificationCenter() removeDeliveredNotification: note];
405 // Clear out (old) reset notifications
406 if (me.circle.isInCircle) {
407 secnotice("kcn", "{ChangeCallback} me.circle.isInCircle");
408 NSUserNotificationCenter *noteCenter = appropriateNotificationCenter();
409 for (NSUserNotification *note in noteCenter.deliveredNotifications) {
410 if (note.userInfo[(NSString*) kValidOnlyOutOfCircleKey]) {
411 secnotice("kcn", "Removing existing notification (%@) now that we are in circle", note);
412 [appropriateNotificationCenter() removeDeliveredNotification: note];
417 //Clear out (old) password changed notifications
418 if(me.circle.isInCircle){
419 secnotice("kcn", "{ChangeCallback} me.circle.isInCircle");
420 NSUserNotificationCenter *noteCenter = appropriateNotificationCenter();
421 for (NSUserNotification *note in noteCenter.deliveredNotifications) {
422 if (note.userInfo[(NSString*) kPasswordChangedOrTrustedDeviceChanged]) {
423 secnotice("kcn", "Removing existing notification (%@) now that we are valid again", note);
424 [appropriateNotificationCenter() removeDeliveredNotification: note];
431 secnotice("kcn", "{ChangeCallback} Applicants");
432 NSMutableSet *applicantIds = [NSMutableSet new];
433 for (KDCirclePeer *applicant in me.circle.applicants) {
434 if (!me.circle.isInCircle) {
435 // Don't yammer on about circles we aren't in, and don't announce our own
436 // join requests as if the user could approve them locally!
439 [me postForApplicant:applicant];
440 [applicantIds addObject:applicant.idString];
444 // Update notifications
445 NSUserNotificationCenter *notificationCenter = appropriateNotificationCenter();
446 secnotice("kcn", "Checking validity of %lu notes", (unsigned long)notificationCenter.deliveredNotifications.count);
447 for (NSUserNotification *note in notificationCenter.deliveredNotifications) {
448 if (note.userInfo[@"applicantId"] && ![applicantIds containsObject:note.userInfo[@"applicantId"]]) {
449 secnotice("kcn", "No longer an applicant (%@) for %@ (I=%@)", note.userInfo[@"applicantId"], note, [note.userInfo compactDescription]);
450 [notificationCenter removeDeliveredNotification:note];
452 secnotice("kcn", "Still an applicant (%@) for %@ (I=%@)", note.userInfo[@"applicantId"], note, [note.userInfo compactDescription]);
456 me.state.lastCircleStatus = circleStatus;
458 [me.state writeToStorage];
463 - (BOOL) userNotificationCenter: (NSUserNotificationCenter *) center
464 shouldPresentNotification: (NSUserNotification *) notification
470 - (void) userNotificationCenter: (NSUserNotificationCenter *) center
471 didActivateNotification: (NSUserNotification *) notification
473 if (notification.activationType == NSUserNotificationActivationTypeActionButtonClicked) {
474 [self notifyiCloudPreferencesAbout:notification.userInfo[@"Activate"]];
479 - (void) userNotificationCenter: (NSUserNotificationCenter *) center
480 didDismissAlert: (NSUserNotification *) notification
482 [self handleDismissedNotification];
484 // If we don't do anything here & another notification comes in we
485 // will repost the alert, which will be dumb.
486 id applicantId = notification.userInfo[@"applicantId"];
487 if (applicantId != nil) {
488 [self.viewedIds addObject:applicantId];
493 - (void) postForApplicant: (KDCirclePeer *) applicant
495 static int postCount = 0;
497 if ([self.viewedIds containsObject:applicant.idString]) {
498 secnotice("kcn", "Already viewed %@, skipping", applicant);
502 NSUserNotificationCenter *noteCenter = appropriateNotificationCenter();
503 for (NSUserNotification *note in noteCenter.deliveredNotifications) {
504 if ([applicant.idString isEqualToString:note.userInfo[@"applicantId"]]) {
505 if (note.isPresented) {
506 secnotice("kcn", "Already posted&presented: %@ (I=%@)", note, note.userInfo);
509 secnotice("kcn", "Already posted, but not presented: %@ (I=%@)", note, note.userInfo);
514 // <rdar://problem/21988060> Improve wording of the iCloud keychain drop/reset error messages
515 // Contrary to HI spec (and I think it makes more sense)
516 // 1. otherButton == top : Not Now
517 // 2. actionButton == bottom: Continue
518 // 3. If we followed HI spec, replace "Activate" => "Dismiss" in note.userInfo below
519 NSUserNotification *note = [NSUserNotification new];
520 note.title = (__bridge_transfer NSString *) SecCopyCKString(SEC_CK_APPROVAL_TITLE_OSX);
521 note.informativeText = [NSString stringWithFormat: (__bridge_transfer NSString *) SecCopyCKString(SEC_CK_APPROVAL_BODY_OSX), applicant.name];
522 note._displayStyle = _NSUserNotificationDisplayStyleAlert;
523 note._identityImage = [NSImage bundleImage];
524 note._identityImageStyle = _NSUserNotificationIdentityImageStyleRectangleNoBorder;
525 note.otherButtonTitle = (__bridge_transfer NSString *) SecCopyCKString(SEC_CK_NOT_NOW);
526 note.actionButtonTitle = (__bridge_transfer NSString *) SecCopyCKString(SEC_CK_CONTINUE);
527 note.identifier = [[NSUUID new] UUIDString];
529 @"applicantName": applicant.name,
530 @"applicantId" : applicant.idString,
531 @"Activate" : (__bridge NSString *) kMMPropertyKeychainAADetailsAEAction,
534 secnotice("kcn", "About to post #%d/%lu (%@): %@", postCount, noteCenter.deliveredNotifications.count, applicant.idString, note);
535 [appropriateNotificationCenter() deliverNotification:note];
539 - (void) postRequirePassword
541 ACAccountStore *accountStore = [[ACAccountStore alloc] init];
542 ACAccount *primaryiCloudAccount = nil;
543 bool localICDP = false;
545 if ([accountStore respondsToSelector:@selector(icaPrimaryAppleAccount)]){
546 primaryiCloudAccount = [accountStore icaPrimaryAppleAccount];
549 if(primaryiCloudAccount){
550 NSString *dsid = primaryiCloudAccount.icaPersonID;
553 NSDictionary *options = @{ (__bridge id) kPCSSetupDSID : dsid, };
554 PCSIdentitySetRef identity = PCSIdentitySetCreate((__bridge CFDictionaryRef) options, NULL, NULL);
557 localICDP = PCSIdentitySetIsICDP(identity, NULL);
562 NSUserNotificationCenter *noteCenter = appropriateNotificationCenter();
563 for (NSUserNotification *note in noteCenter.deliveredNotifications) {
564 if (note.userInfo[(NSString*) kPasswordChangedOrTrustedDeviceChanged]) {
565 if (note.isPresented) {
566 secnotice("kcn", "Already posted & presented: %@", note);
567 [appropriateNotificationCenter() removeDeliveredNotification: note];
569 secnotice("kcn", "Already posted, but not presented: %@", note);
574 NSString *message = CFBridgingRelease(SecCopyCKString(SEC_CK_PWD_REQUIRED_BODY_OSX));
575 if (isAppleInternal()) {
576 NSString *reason_str = [NSString stringWithFormat:(__bridge_transfer NSString *) SecCopyCKString(SEC_CK_CR_REASON_INTERNAL), @"Device became untrusted or password changed"];
577 message = [message stringByAppendingString: reason_str];
580 NSUserNotification *note = [NSUserNotification new];
581 note.title = (__bridge_transfer NSString *) SecCopyCKString(SEC_CK_PWD_REQUIRED_TITLE);
582 note.informativeText = message;
583 note._identityImage = [NSImage bundleImage];
584 note._identityImageStyle = _NSUserNotificationIdentityImageStyleRectangleNoBorder;
585 note.otherButtonTitle = (__bridge_transfer NSString *) SecCopyCKString(SEC_CK_NOT_NOW);
586 note.actionButtonTitle = (__bridge_transfer NSString *) SecCopyCKString(SEC_CK_CONTINUE);
587 note.identifier = [[NSUUID new] UUIDString];
590 kPasswordChangedOrTrustedDeviceChanged : @1,
591 @"Activate" : (__bridge NSString *) kMMPropertyKeychainPCDetailsAEAction,
594 secnotice("kcn", "body=%@", note.informativeText);
595 secnotice("kcn", "About to post #-/%lu (PASSWORD/TRUSTED DEVICE): %@", noteCenter.deliveredNotifications.count, note);
596 [appropriateNotificationCenter() deliverNotification:note];
599 secnotice("kcn","would have posted needs password and then followed up");
600 [self startFollowupKitRepair];
605 - (void) postKickedOutAlert: (int) reason
607 ACAccountStore *accountStore = [[ACAccountStore alloc] init];
608 ACAccount *primaryiCloudAccount = nil;
609 bool localICDP = false;
611 if ([accountStore respondsToSelector:@selector(icaPrimaryAppleAccount)]){
612 primaryiCloudAccount = [accountStore icaPrimaryAppleAccount];
615 if(primaryiCloudAccount){
616 NSString *dsid = primaryiCloudAccount.icaPersonID;
619 NSDictionary *options = @{ (__bridge id) kPCSSetupDSID : dsid, };
620 PCSIdentitySetRef identity = PCSIdentitySetCreate((__bridge CFDictionaryRef) options, NULL, NULL);
623 localICDP = PCSIdentitySetIsICDP(identity, NULL);
628 NSUserNotificationCenter *noteCenter = appropriateNotificationCenter();
629 for (NSUserNotification *note in noteCenter.deliveredNotifications) {
630 if (note.userInfo[(NSString*) kKickedOutKey]) {
631 if (note.isPresented) {
632 secnotice("kcn", "Already posted&presented (removing): %@", note);
633 [appropriateNotificationCenter() removeDeliveredNotification: note];
635 secnotice("kcn", "Already posted, but not presented: %@", note);
640 NSString *message = CFBridgingRelease(SecCopyCKString(SEC_CK_PWD_REQUIRED_BODY_OSX));
641 if (isAppleInternal()) {
642 static const char *departureReasonStrings[] = {
643 "kSOSDepartureReasonError",
644 "kSOSNeverLeftCircle",
645 "kSOSWithdrewMembership",
646 "kSOSMembershipRevoked",
647 "kSOSLeftUntrustedCircle",
648 "kSOSNeverAppliedToCircle",
649 "kSOSDiscoveredRetirement",
650 "kSOSLostPrivateKey",
653 int idx = (kSOSDepartureReasonError <= reason && reason <= kSOSLostPrivateKey) ? reason : (kSOSLostPrivateKey + 1);
654 NSString *reason_str = [NSString stringWithFormat:(__bridge_transfer NSString *) SecCopyCKString(SEC_CK_CR_REASON_INTERNAL), departureReasonStrings[idx]];
655 message = [message stringByAppendingString: reason_str];
658 // <rdar://problem/21988060> Improve wording of the iCloud keychain drop/reset error messages
659 // Contrary to HI spec (and I think it makes more sense)
660 // 1. otherButton == top : Not Now
661 // 2. actionButton == bottom: Continue
662 // 3. If we followed HI spec, replace "Activate" => "Dismiss" in note.userInfo below
663 NSUserNotification *note = [NSUserNotification new];
664 note.title = (__bridge_transfer NSString *) SecCopyCKString(SEC_CK_PWD_REQUIRED_TITLE);
665 note.informativeText = message;
666 note._identityImage = [NSImage bundleImage];
667 note._identityImageStyle = _NSUserNotificationIdentityImageStyleRectangleNoBorder;
668 note.otherButtonTitle = (__bridge_transfer NSString *) SecCopyCKString(SEC_CK_NOT_NOW);
669 note.actionButtonTitle = (__bridge_transfer NSString *) SecCopyCKString(SEC_CK_CONTINUE);
670 note.identifier = [[NSUUID new] UUIDString];
674 kValidOnlyOutOfCircleKey: @1,
675 @"Activate" : (__bridge NSString *) kMMPropertyKeychainMRDetailsAEAction,
678 secnotice("kcn", "body=%@", note.informativeText);
679 secnotice("kcn", "About to post #-/%lu (KICKOUT): %@", noteCenter.deliveredNotifications.count, note);
680 [appropriateNotificationCenter() deliverNotification:note];
684 secnotice("kcn","postKickedOutAlert starting followup repair");
685 [self startFollowupKitRepair];
690 - (void) postApplicationReminder
692 NSUserNotificationCenter *noteCenter = appropriateNotificationCenter();
693 for (NSUserNotification *note in noteCenter.deliveredNotifications) {
694 if (note.userInfo[@"ApplicationReminder"]) {
695 if (note.isPresented) {
696 secnotice("kcn", "Already posted&presented (removing): %@", note);
697 [appropriateNotificationCenter() removeDeliveredNotification: note];
699 secnotice("kcn", "Already posted, but not presented: %@", note);
704 // <rdar://problem/21988060> Improve wording of the iCloud keychain drop/reset error messages
705 // Contrary to HI spec (and I think it makes more sense)
706 // 1. otherButton == top : Not Now
707 // 2. actionButton == bottom: Continue
708 // 3. If we followed HI spec, replace "Activate" => "Dismiss" in note.userInfo below
709 NSUserNotification *note = [NSUserNotification new];
710 note.title = (__bridge_transfer NSString *) SecCopyCKString(SEC_CK_REMINDER_TITLE_OSX);
711 note.informativeText = (__bridge_transfer NSString *) SecCopyCKString(SEC_CK_REMINDER_BODY_OSX);
712 note._identityImage = [NSImage bundleImage];
713 note._identityImageStyle = _NSUserNotificationIdentityImageStyleRectangleNoBorder;
714 note.otherButtonTitle = (__bridge_transfer NSString *) SecCopyCKString(SEC_CK_NOT_NOW);
715 note.actionButtonTitle = (__bridge_transfer NSString *) SecCopyCKString(SEC_CK_CONTINUE);
716 note.identifier = [[NSUUID new] UUIDString];
719 @"ApplicationReminder" : @1,
720 kValidOnlyOutOfCircleKey: @1,
721 @"Activate" : (__bridge NSString *) kMMPropertyKeychainWADetailsAEAction,
724 secnotice("kcn", "About to post #-/%lu (REMINDER): %@ (I=%@)", noteCenter.deliveredNotifications.count, note, [note.userInfo compactDescription]);
725 [appropriateNotificationCenter() deliverNotification:note];